package org.edu.modules.scheduleCommon.dto;

import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class AttendanceExport {
    public static void main(String[] args) throws Exception {
        // 1. 准备数据
        List<AttendanceData> dataList = new ArrayList<>();
        for (int i = 1; i <= 5; i++) { // 模拟5天数据
            AttendanceData model = new AttendanceData();
            model.setWeekHeader("星期" + (i < 6 ? i : "五"));
            model.setPeriod1("考勤数据-" + i + "-1");
            model.setPeriod2("考勤数据-" + i + "-2");
            // ... 设置其他节次数据
            dataList.add(model);
        }

        // 2. 输出文件配置
        FileOutputStream out = new FileOutputStream("D:/考勤表.xlsx");
        ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);

        // 3. 注册表头合并处理器
        //writer.registerWriteHandler(new AttendanceData.HeaderMergeHandler());

        // 4. 写入数据
        Sheet sheet = new Sheet(1, 0, AttendanceData.class);
        sheet.setSheetName("考勤明细");
        writer.write(dataList, sheet);

        // 5. 关闭资源
        writer.finish();
        out.close();
        System.out.println("导出成功！路径: D:/考勤表.xlsx");
    }
}
